home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
weapons
/
Homing Missile.lua
< prev
next >
Wrap
Text File
|
2010-09-22
|
7KB
|
186 lines
--------------------------------------------------------------------------------
-- Weapon Homing Missile Launcher + Projectile Missile
-- Original Carnage Contest Weapon
-- Script by DC, August 2009, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.homing={}
cc.homing.missile={}
-- Load & Prepare Ressources
cc.homing.gfx_wpn=loadgfx("weapons/launcher.bmp") -- Weapon Image
setmidhandle(cc.homing.gfx_wpn)
cc.homing.gfx_pro=loadgfx("weapons/homingmissile.bmp") -- Projectile Image
setmidhandle(cc.homing.gfx_pro)
cc.homing.sfx_attack=loadsfx("rocketrelease.wav") -- Attack Sound
cc.homing.sfx_homing=loadsfx("homing.wav") -- Homing Sound
--------------------------------------------------------------------------------
-- Weapon: Homing Missile Launcher
--------------------------------------------------------------------------------
cc.homing.id=addweapon("cc.homing","Homing Missile",cc.homing.gfx_pro,1,2) -- Add Weapon (1 use, first in round 2)
function cc.homing.draw() -- Draw
setblend(blend_alpha)
setalpha(1)
setcolor(120,180,255)
drawinhand(cc.homing.gfx_wpn,6,0)
-- HUD chargebar
if weapon_charge>0 and weapon_shots==0 then
hudchargebar(weapon_charge,100)
end
-- HUD Crosshair + Positioning
if weapon_shots==0 then
hudcrosshair(6,3)
hudpositioning(pos_normal)
end
end
function cc.homing.attack(attack) -- Attack
if (weapon_shots<=0) and(weapon_position==1) then
-- Charge
if (attack==1) then
weapon_charge=weapon_charge+1 -- Increase charge
end
-- Fire a projectile (on release/full charge)
if (attack==0 and weapon_charge>0) or (weapon_charge>=100) then
-- No more weapon switching!
useweapon(0)
playsound(cc.homing.sfx_attack)
weapon_shots=weapon_shots+1
id=createprojectile(cc.homing.missile.id)
projectiles[id]={}
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(6*getplayerdirection(0))+math.sin(math.rad(getplayerrotation(0)))*10.0
projectiles[id].y=getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*10.0
-- Set Timer (time until homing, 1 sec)
projectiles[id].timer=50
-- Initial movement
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*20
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*20
projectiles[id].x=projectiles[id].x-projectiles[id].sx
projectiles[id].y=projectiles[id].y-projectiles[id].sy
cc.homing.missile.move(id,0)
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
projectiles[id].sy=-math.cos(math.rad(getplayerrotation(0)))*(weapon_charge/100.0)*10.0
-- Effects
recoil(2)
-- End Turn
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: Missile
--------------------------------------------------------------------------------
cc.homing.missile.id=addprojectile("cc.homing.missile") -- Add Projectile
function cc.homing.missile.draw(id) -- Draw
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.homing.gfx_pro,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.homing.missile.update(id) -- Update
cc.homing.missile.move(id,1)
end
function cc.homing.missile.move(id,fx)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Particle Tail
if (fx==1) then
particle(p_smoke,projectiles[id].x-math.sin(math.rad(rot))*7,projectiles[id].y+math.cos(math.rad(rot))*7)
particlespeed(math.random(-2,2)*0.1,math.random(-2,2)*0.1)
particlefadealpha(0.01)
if projectiles[id].timer<0 and projectiles[id].timer>-250 then
particle(p_lightpuff,projectiles[id].x-math.sin(math.rad(rot))*6,projectiles[id].y+math.cos(math.rad(rot))*6)
particlefadealpha(0.04)
end
end
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()
projectiles[id].sy=projectiles[id].sy+getgravity()
-- Homing
explode=0
if (fx==1) then
projectiles[id].timer=projectiles[id].timer-1
end
if projectiles[id].timer<=0 and projectiles[id].timer>-250 then
-- Start Homing FX
if projectiles[id].timer==0 then
playsound(cc.homing.sfx_homing)
particle(p_ring,projectiles[id].x,projectiles[id].y)
particlecolor(0,150,255)
end
-- Homing Calculation
aimangle=math.deg(math.atan2(weapon_x-projectiles[id].x,-(weapon_y-projectiles[id].y)))
speed=math.sqrt(math.pow(projectiles[id].sx,2)+math.pow(projectiles[id].sy,2))
if speed<8.0 then
speed=speed+0.15
if speed>8.0 then speed=8.0 end
end
rot=rot+angledelta(rot,aimangle)*0.08
projectiles[id].sx=math.sin(math.rad(rot))*speed
projectiles[id].sy=-math.cos(math.rad(rot))*speed
-- Timeout
if projectiles[id].timer<=-250 then
explode=1
end
end
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*3,projectiles[id].y-math.cos(math.rad(rot))*3)==1 or explode==1 then
if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore or explode==1 then
-- Cause damage
arealdamage(projectiles[id].x,projectiles[id].y,100,40)
-- Destroy terrain
terrainexplosion(projectiles[id].x,projectiles[id].y,25,1)
-- Crater
grey=math.random(0,40)
if math.random(0,1)==1 then
terrainalphaimage(gfx_crater100,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
else
terrainalphaimage(gfx_crater125,projectiles[id].x,projectiles[id].y,math.random(6,9)*0.1,grey,grey,grey)
end
-- Free projectile
freeprojectile(id)
break
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
playsound(sfx_hitwater1)
-- Free projectile
freeprojectile(id)
break
end
end
-- Scroll to projectile
scroll(projectiles[id].x,projectiles[id].y)
end